package com.deviche.gank;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.deviche.library.net.NetHelper;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

    public static final String TAG = MainActivity.class.getSimpleName() + "---gank----";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        getData();
    }

    private void getData() {
        NetHelper.init();
//        Log.e(TAG, "getData: 8888888888888888888");
        CallService callService = NetHelper.getRetrofit().create(CallService.class);

        Observable<DataBean> data = callService.getData();

        data.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Observer<DataBean>() {

            @Override
            public void onError(Throwable e) {
                Log.e(TAG, "onError: +777777777777" + e.getMessage());
            }

            @Override
            public void onComplete() {
                Log.e(TAG, "onComplete: +999999999999999999");
            }

            @Override
            public void onSubscribe(Disposable d) {
                Log.e(TAG, "onSubscribe: +444444444444");
            }

            @Override
            public void onNext(DataBean value) {
                Log.e(TAG, "onNext: ---------" + value.getResults().getApp().size());
            }

        });

    }
}
